{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-content"> 
				<div class="row row-lg"> 
					<div class="col-sm-12"> 
						<div class="row" id="searchGroup">
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">手机号</button>
									</div>
									<input type="text" autocomplete="off" class="form-control" id="phone" placeholder="手机号" />
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">性别</button>
									</div>
									<select class="form-control" id="sex">
										<option value="">请选择</option>
										<option value="1">男</option>
										<option value="2">女</option>
										<option value="0">未知</option>
									</select>
								</div>
							</div>
							<div class="col-sm-2">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">等级</button>
									</div>
									<select class="form-control" id="level">
										<option value="">请选择</option>
										<option value="0">未购买</option>
										<option value="1">基础版</option>
										<option value="2">完整版</option>
										<option value="3">VIP</option>
									</select>
								</div>
							</div>
							<!-- search end -->
							<div class="col-sm-1">
								<button type="button" class="btn btn-success " onclick="CodeGoods.search()" id="">
									<i class="fa fa-search"></i>&nbsp;搜索
								</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
 			{field: 'selectItem', checkbox: true},
 			{title: '编号', field: 'u_id', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '昵称', field: 'nickname', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '手机号', field: 'phone', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '注册时间', field: 'add_time', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.add_timeFormatter},
 			{title: '头像', field: 'headimgurl', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.headimgurlFormatter},
 			{title: '性别', field: 'sex', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.sexFormatter},
 			{title: '城市', field: 'city', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '省', field: 'province', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '微信标识', field: 'openid', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '上级id', field: 'pid', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '上级昵称', field: 'pnickname', visible: true, align: 'center', valign: 'middle',sortable: true},
 			{title: '上级头像', field: 'pheadimgurl', visible: true, align: 'center', valign: 'middle',sortable: true,formatter:CodeGoods.pheadimgurlFormatter},
 		];
 	};

	CodeGoods.add_timeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value,'Y-m-d H:i:s');	
		}
	}

	CodeGoods.headimgurlFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";	
		}
	}

	CodeGoods.sexFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">男</span>';
				break;
				case '2':
					return '<span class="label label-warning">女</span>';
				break;
				case '0':
					return '未知';
				break;
			}
		}
	}

	CodeGoods.pheadimgurlFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";	
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['offset'] = 0;
		queryData['phone'] = $("#phone").val();
		queryData['sex'] = $("#sex").val();
		queryData['level'] = $("#level").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/Users.Index/index"+url,defaultColunms,20);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>
{/block}